<?php
	session_start();
	require_once('../includes/user.php');
	$user=new User();
	$q_type_res=$user->query("select quiz_type from quiz_names where quiz_id = '$_POST[id]' ");
	$q_type_row=mysql_fetch_array($q_type_res);
	if($q_type_row['quiz_type']!=3)
	{
		$result=$_POST['len'];
		$answer=explode(':()%#@',$_POST['answer']);
		$ques=explode(':',$_POST['ques']);
		for($i=0;$i<$_POST['len'];$i++)
		{
			$qb_answer_res=$user->query("select answer from quiz_question_bank where id=$ques[$i]");
			$qb_answer_row=mysql_fetch_array($qb_answer_res);
			if($qb_answer_row['answer']!=$answer[$i])
			{
				$result=$result-1;
			}
		}
		$pat=$_POST['len']/10;
		$getu=$result/$pat;
		$pt_res=$user->query("select * from quiz_point_limit where '$getu' between lower and higher ORDER BY higher");
		$pt_row=mysql_fetch_array($pt_res);
		$pts=$pt_row['pts'];
		$user->updateQuizHistory($_SESSION['id'],$_POST['id'],$result."/".$_POST['len'],$pts);
	}
	else
	{
		$answer=explode(':()%#@',$_POST['answer']);
		$ques=explode(':',$_POST['ques']);
		for($i=0;$i<$_POST['len'];$i++)
		{
			$user->record['test_id']=$_POST['id'];
			$user->record['ques_id']=$ques[$i];
			$user->record['profile_id']=$_SESSION['id'];
			$user->record['answer']=$answer[$i];
			$user->save('quiz_short');
		}
		$user->updateQuizHistory($_SESSION['id'],$_POST['id'],'Valuation in progress',0);
	}
?>